@extends('admin.layouts.main_slight')
@section('content')

<style>
    body{padding: 10px;}
</style>
<?php

use App\Extend\Admin\Common\Html\EasyForm;
use App\Http\Admin\Models\Fields\System\Icon;
$get = $get ?? [];

$easyForm = new EasyForm($get, Icon::class);
?>
<body>

<!-- 内容主体区域 -->
<div style="padding: 15px;">
	<?php

    $url = empty($get['id']) ? './add' : './update';
	?>
	<form class="layui-form layui-form-pane1" method="post" action="<?php echo $url; ?>" lay-filter="first">
	@csrf
		<?php
		echo $easyForm->hidden('id');
		echo $easyForm->text('icon');
        echo $easyForm->text('desc');
        
		?>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="*">提交</button>
				<button onclick="closeIframe();" type="button" class="layui-btn">取消</button>
			</div>
		</div>
	</form>

	<br><br><br>

	<script>

		layui.use('form', function(){
			const $ = layui.$;
			const form = layui.form;

			//自定义验证规则
			form.verify({

			});

			//监听提交
			form.on('submit(*)', function(data){
				$.post('<?php echo $url ?>' , data.field , function(d) {
					console.log(d.code);
					if(d.code != 0) {
						//返回失败
						layer.msg(d.msg);
						return false;
					}
					layer.msg('成功');
					setTimeout(function() {
						const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭
						parent.layui.table.reload('list');
					},1000);
				});
				return false;
			});

		});

	</script>
</div>

</body>

@endsection